package com.leetcode.algorithm.y22.m08.w5;

import java.util.Arrays;

/**
 * 1984. 学生分数的最小差值
 * 
 * https://leetcode.cn/problems/maximum-average-subarray-i/
 * 
 * @author jie.deng
 *
 */
class Question1984Solution01 {

	public int minimumDifference(int[] nums, int k) {
		if (k == 1) {
			return 0;
		}
		Arrays.sort(nums);
		int len = nums.length;
		int minimumDifference = Integer.MAX_VALUE;
		int left = 0;
		for (int right = k - 1; right < len; right++) {
			minimumDifference = Math.min(minimumDifference, nums[right] - nums[left]);
			left++;
		}
		return minimumDifference;
	}

}